<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        .box{width: 100px;height: 100px;background: red;position: absolute;left:0;top:0;}
        .line{width:1px;height: 500px;background: black;position: absolute;left:500px;top:0;}
    </style>
</head>
<body>
    <div class="box"></div>
    <div class="line"></div>
</body>
<script>
    const obox = document.querySelector(".box")

    let t;
    let speed = 2;
    let target = 500;

    document.onclick = function(){
        clearInterval(t);
        t = setInterval(() => {
            if(target - obox.offsetLeft < speed){
                clearInterval(t);
                obox.style.left = target + "px";
            }else{
                obox.style.left = obox.offsetLeft + speed + "px";
            }
        }, 30);
    }

</script>
</html>